// pages/Tabbar/Home/Home.js
//获取应用实例
const app = getApp()
const assetsAddress = app.globalData.global.assetsIp + '/' + app.globalData.global.assetsName;
import { getBusinessManage , getShareConfig } from '../../../api/home';
import { Login } from '../../../store/user';

Page({
  callPhone(){
    wx.makePhoneCall({
      phoneNumber: this.data.customerService.phone,
    })
  },
  addWX(){
    wx.setClipboardData({
      data:this.data.customerService.wxNum,
      success(res){
        //   console.log('是否成功')
      },
      fail(err){
          console.log(err)
      }
    })
  },
  /**
   * 页面的初始数据
   */
  data: {
    avatar: 'https://gejin-test.oss-cn-shanghai.aliyuncs.com/image/WechatIMG459.jpeg',
    customerService:{"url":"https://gejin-test.oss-cn-shanghai.aliyuncs.com/image/WechatIMG459.jpeg","nickName":'你的专属经理！',"phone":"18888888888","wxNum":"hhhhhh"},
    flowDatas:[{"arrowicon":assetsAddress+"/home/home_arrow_mark.png","flowIcon":assetsAddress+"/home/flow_commend_client.png","title":"推荐客户","des":"推荐客户给平台\n商务经理"},{"arrowicon":assetsAddress+"/home/home_arrow_mark.png","flowIcon":assetsAddress+"/home/flow_bindin_client.png","title":"绑定客户","des":"平台成交客户\n个人绑定客户"},
    {"arrowicon":assetsAddress+"/home/home_arrow_mark.png","flowIcon":assetsAddress+"/home/flow_client_payment.png","title":"客户走款","des":"客户产生交易\n个人查看交易"},
    {"arrowicon":"","flowIcon":assetsAddress+"/home/flow_get_amount.png","title":"提取佣金","des":"平台按提分佣\n给个人"}],
    questions:[
      // {"title":"1、哪些是我们的客户群？","content":"具有建设工程施工需求以及税源地分包需求的税源地公司，如上海建工集团、浦东建设集团，以及大型全国性的地产集团，如上海绿地、广州恒大、龙湖地产等税源地业企业"},
      {"title":"1、我们为客户提供什么价值？","content":"公司经过十多年的业务积累，结合当下国家保证农民工工资及时发放政策，运用互联网+思维和成熟的软件开发运用能力，和招商银行技术开发创新部门通力合作，开发了一套安全便捷的税源地工程行业民工工资代发的联动系统，为税源地公司和民工、包工头的工资发放提供了一个安全通道。"},
      {"title":"2、如何推广客户？","content":"采集客户资源，联系您的专属商务经理即可"},
      {"title":"3、如何实现躺赚人生？","content":"推荐给商务经理的客户确认合作，通过系统完成交易后，推荐人即可获取佣金，您也可以分享小程序给下级，下级客户成交，同样可获取佣金"},
    ],
    assetsAddress: assetsAddress,
    platformRate: 0, // 平台分佣比例
    oneLevelRateHasParent: 0, // 直推分佣比例（有上级）
    oneLevelRateNoParent: 0, // 直推分佣比例（无上级）
    twoLevelRate: 0, // 间推分佣比例
    serviceRate: 0, // 服务费比例
    firstGrant: 1, // 是否仅首次结算产生佣金，1：是，0：否
    shareTitle: app.globalData.global.shareTitle,
    showPrivacyAuthor: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if(options.scene){
      const scene = decodeURIComponent(options.scene)
      wx.setStorageSync('preUserId', scene)
    }
    this.getManage();
    this.getShareConfigs();
    Login({noToast: true});
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var _this = this;
    if (wx.onNeedPrivacyAuthorization){
      wx.onNeedPrivacyAuthorization((resolve) => {
        console.log('触发弹窗')
        // 触发弹窗
        _this.setData({
          showPrivacyAuthor: true,
        })
        _this.resolvePrivacyAuthorization = resolve
        console.log(resolve,resolve);
      })
    }  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    let userId = wx.getStorageSync('userId')
    return {
      title: this.data.shareTitle,
      path: '/pages/Tabbar/Home/Home?scene='+userId,
    }
  },
  // 获取商务经理
  getManage(){
    let _this = this;
    getBusinessManage()
    .then(res => {
      if(res.success){
        if(res.data){
          _this.setData({
            customerService: res.data
          })
        }
      }else{
        wx.showToast({
          title: res.errMessage,
          icon: 'none',
        })
      }
    })
  },
  // 获取推广佣金配置
  getShareConfigs(){
    let _this = this;
    getShareConfig()
    .then(res => {
      if(res.success){
        if(res.data.id){
          _this.setData({
            platformRate: res.data.platformRate,
            oneLevelRateHasParent: res.data.oneLevelRateHasParent,
            oneLevelRateNoParent: res.data.oneLevelRateNoParent,
            twoLevelRate: res.data.twoLevelRate,
            serviceRate: res.data.serviceRate,
            firstGrant: res.data.firstGrant,
          })
        }
      }else{
        wx.showToast({
          title: res.errMessage,
          icon: 'none',
        })
      }
    })
  },
  handleAgreePrivacyAuthorizationFun(){
    console.log('同意之后的回调');
  },
  disagreePrivacyAuthorization(){
    this.resolvePrivacyAuthorization({ event: 'disagree' });
  },
})